﻿#include "setuptotalwind.h"
#include "ui_setuptotalwind.h"
#include <mainwindow.h>
extern intListener doorStatus;
setuptotalwind::setuptotalwind(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::setuptotalwind)
{
    setWindowIcon(QIcon(":/pic/picture/kafavicon.ico"));
    ui->setupUi(this);
    connect(&doorStatus, &intListener::valueChanged,this,&setuptotalwind::doorStatusChanged,Qt::QueuedConnection);
    ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    ui->pushButton_5->setEnabled(false);
}
void setuptotalwind::doorStatusChanged(){
    if(doorStatus.get()==0)
    {
        ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
}

setuptotalwind::~setuptotalwind()
{
    delete ui;
}
void setuptotalwind::showEvent(QShowEvent *event)
{
    tcpClient = TcpClient::getInstance();

    if(doorStatus.get()==0)
    {
        ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    event->accept();
}

void setuptotalwind::on_returnMainBtn_clicked()
{
    this->close();
    emit changeMainWindow();
}

void setuptotalwind::on_pushButton_clicked()
{
    this->close();
    emit changeSetUp1Window();
}

void setuptotalwind::on_pushButton_2_clicked()
{
    this->close();
    emit changeSetUp2Window();
}

void setuptotalwind::on_pushButton_3_clicked()
{
    this->close();
    emit changeSetUp3Window();
}

void setuptotalwind::on_pushButton_6_clicked()
{
    this->close();
    emit changeSetUp4Window();
}

void setuptotalwind::on_pushButton_7_clicked()
{
    this->close();
    emit changeSetUp5Window();
}

void setuptotalwind::on_pushButton_8_clicked()
{
    this->close();
    emit changeSetUp6Window();
}

void setuptotalwind::on_pushButton_9_clicked()
{
    this->close();
    emit changeSetUp7Window();
}

void setuptotalwind::on_pushButton_10_clicked()
{
    // 创建一个QWidget作为容器
    QWidget *container = new QWidget;
    container->setAttribute(Qt::WA_QuitOnClose, false);
    container->setWindowIcon(QIcon(":/pic/picture/kafavicon.ico"));
    container->setWindowTitle("关于我们");

    container->setStyleSheet("background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 #007bd8,stop:0.5 #474ac1 ,stop:1 #001a5a)");
    // 创建一个QLabel
    QLabel *label = new QLabel(container); // 设置container为parent
    label->setMinimumSize(500, 400);
    label->setWordWrap(true); // 启用自动换行
    // 设置字号（字体大小）
    QFont font = label->font();
    font.setPointSize(12); // 设置字体大小为 12 点
    label->setFont(font);
    label->setStyleSheet("QLabel { background: rgba(255,255,255,0.76); }");
    label->setAlignment(Qt::AlignCenter); // 这将使文本在 QLabel 内部居中

    label->setText("    软件名称:CardType-Chip Analysis Software \n 软件版本:V1.8 \n 公司名称:长春市博坤生物科技有限公司\n"
                   "声明:本软件仅限于生物研究,不可用于生物诊断;");

    // 创建一个QPushButton
    QPushButton *button = new QPushButton("返回", container); // 设置container为parent
    font = button->font();
    font.setPointSize(12); // 设置字体大小为 12 点
    button->setStyleSheet("QPushButton { background: rgba(255,255,255,0.76); }");

    // 创建一个垂直布局
    QVBoxLayout *layout = new QVBoxLayout(container);

    // 将QLabel和QPushButton添加到布局中
    layout->addWidget(label); // label将占据大部分空间
    layout->addWidget(button); // button将显示在label下方

    // 设置container的布局为刚才创建的QVBoxLayout（这步其实已经在new QVBoxLayout(container)时完成了）

    // 如果container是某个窗口或对话框的子控件，你需要将其显示出来
    // 连接按钮的clicked信号到QWidget的close槽
    connect(button, &QPushButton::clicked, container, &QWidget::close);
    connect(ui->returnMainBtn, &QPushButton::clicked, container, &QWidget::close);
    container->show(); // 显示container，label和button会自动显示，因为它们是container的子控件
}

void setuptotalwind::on_pushButton_11_clicked()
{
    helpfileui = new helpfile();
    helpfileui->show();
}

void setuptotalwind::on_pushButton_5_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
        ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        doorStatus.set(0);
        ui->pushButton_5->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
}

